/*
 * Copyright 2023 AntGroup CO., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

package com.antgroup.geaflow.shuffle.network.protocol;

import io.netty.channel.FileRegion;
import io.netty.util.AbstractReferenceCounted;

/**
 * This class is an adaptation of Spark's org.apache.spark.network.util.AbstractFileRegion.
 */
public abstract class AbstractFileRegion extends AbstractReferenceCounted implements FileRegion {

    protected int chunkSize = 64 * 1024 * 1024;

    protected long transferred;
    protected long contentSize;

    public AbstractFileRegion(long contentSize) {
        this.transferred = 0;
        this.contentSize = contentSize;
    }

    @Override
    public final long transfered() {
        return transferred();
    }

    @Override
    public long position() {
        return 0;
    }

    @Override
    public long transferred() {
        return transferred;
    }

    @Override
    public long count() {
        return contentSize;
    }

    @Override
    public AbstractFileRegion retain() {
        super.retain();
        return this;
    }

    @Override
    public AbstractFileRegion retain(int increment) {
        super.retain(increment);
        return this;
    }

    @Override
    public AbstractFileRegion touch() {
        super.touch();
        return this;
    }

    @Override
    public AbstractFileRegion touch(Object o) {
        return this;
    }

}
